home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
C64
/
A-Monthly Disks
/
(c)aaw.d64
/
d2f
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2007-02-04
|
1KB
|
62 lines
10 REM DECIMAL TO FRACTION CONVERTOR
20 REM BY R. H. YOUNG;APRIL,1988
100 PRINT"[147]"
110 PRINT"PRESS 1 TO REDUCE A FRACTION.":PRINT
120 PRINT"PRESS 2 TO OBTAIN A FRACTION"
130 PRINT"FROM AN EXACT DECIMAL (<=9 DIGITS).":PRINT
140 PRINT"PRESS 3 TO OBTAIN A FRACTION"
150 PRINT"FROM A DECIMAL.":PRINT
155 PRINT"PRESS 4 TO END.":PRINT
160 GET A$:IF A$=""THEN 160
170 V=VAL(A$)
180 ON V GOTO 200,250,330,490
190 GOTO 160
200 PRINT"[147]":INPUT"INPUT NUMERATOR";N
210 INPUT"INPUT DENOMINATOR";D
215 N=ABS(N):D=ABS(D)
220 GOSUB 500
230 PRINT:PRINT"NUMERATOR="N
240 PRINT"DENOMINATOR="D
245 PRINT:GOTO 110
250 PRINT"[147]":INPUT"INPUT DECIMAL";A
255 A=ABS(A)
260 C=INT(A):L=A-C
270 D=1E9:N=D*L
280 GOSUB 500
290 N=N+C*D
300 PRINT:PRINT"NUMERATOR="N
310 PRINT"DENOMINATOR="D
320 PRINT:GOTO 110
330 PRINT"[147]":INPUT"INPUT DECIMAL";A
340 PRINT:INPUT"INPUT MAXIMUM ERROR";B
350 A=ABS(A):B=ABS(B)
370 C=INT(A):L=A-C:R=0
380 IF L>.5 THEN L=1-L:R=1
390 IF L=.5 THEN 430
395 D=4:N=INT(4*L)
400 GOSUB 575
410 IF R=1 THEN N=D-N
420 GOTO 440
430 N=1:D=2:E=0
440 N=N+C*D:GOSUB 500
450 PRINT:PRINT"NUMERATOR="N
460 PRINT"DENOMINATOR="D
470 PRINT"ERROR="E
480 PRINT:GOTO 110
490 END
500 IF N>D THEN 520
510 H=N:I=D:GOTO 530
520 H=D:I=N
530 J=I/H:K=I-H*INT(J)
540 I=H:H=K:IF K=0 THEN 560
550 GOTO 530
560 N=N/I:D=D/I
570 RETURN
575 NI=1
580 PRINT"ITERATION"NI
590 E=L-N/D:F=ABS(E)
600 IF F<B THEN RETURN
610 IF E>0 THEN 630
620 D=D+1:N=INT(D*L+.5):NI=NI+1:GOTO 580
630 N=N+1:D=INT(N/L+.5):NI=NI+1:GOTO 580